package com.chezhujie.www.controller;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.codehaus.jackson.JsonParseException;
import org.codehaus.jackson.map.JsonMappingException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.chezhujie.www.core.page.Pagination;
import com.chezhujie.www.domain.Czjfestivalact;
import com.chezhujie.www.domain.Czjfestpic;
import com.chezhujie.www.service.CzjfestivalactService;
import com.chezhujie.www.service.CzjfestpicService;
import com.chezhujie.www.utils.ConvertObj;

@Controller
@RequestMapping("/festivalactApi")
public class CzjfestivalactControllerApi extends BaseController {
	private static final Logger log = LoggerFactory
			.getLogger(CzjfestivalactControllerApi.class);

	public CzjfestivalactControllerApi() {
	}

	/**
	 * 
	 * 方法名：listThree 显示在首页的假日活动
	 * 创建人：RUI
	 * 时间：2017年5月23日-下午2:38:17 
	 * @param czjfestivalact
	 * @param request
	 * @param pageNo
	 * @param pageSize
	 * @param response
	 * @param modelMap void
	 * @exception 
	 * @since  1.0.0
	 */
	@RequestMapping(value = "listUp")
	public void listThree(Czjfestivalact czjfestivalact,
			HttpServletRequest request, Integer pageNo, Integer pageSize,
			HttpServletResponse response, ModelMap modelMap) {

		try {
			List<Czjfestivalact> czjfestivalacts = festivalactService
					.getFestListUp();
			jsonResult(1, "", "", czjfestivalacts, response);
		} catch (Exception e) {
			e.printStackTrace();
			log.error("error",e);
			jsonResult(0, "121", "查询显示首页假日活动失败", "", response);
		}
	}
	/**
	 * 
	 * 方法名：list 显示所有假日活动详情 创建人：RUI 时间：2017年5月23日-下午1:58:19
	 * 
	 * @param czjfestivalact
	 * @param request
	 * @param response
	 * @param pageNo
	 * @param pageSize
	 * @param modelMap
	 *            void
	 * @exception
	 * @since 1.0.0
	 */
	@RequestMapping(value = "list")
	public void list(Czjfestivalact czjfestivalact, HttpServletRequest request,
			HttpServletResponse response, Integer pageNo, Integer pageSize,
			ModelMap modelMap) {

		try {
			if (null == pageNo)
				pageNo = 1;
			if (null == pageSize)
				pageSize = 20;
			czjfestivalact.setExt3(0);//显示未删除
			Pagination pagination = festivalactService.getFestList(
					ConvertObj.toMap(czjfestivalact), pageSize, pageNo);
			jsonResult(1, "", "", pagination, response);
		} catch (Exception e) {
			e.printStackTrace();
			log.error("error",e);
			jsonResult(0, "122", "查询假日活动错误", "", response);
		}

	}

	/***
	 * 方法名：detail 显示假日活动详情
	 * 创建人：RUI
	 * 时间：2017年5月23日-下午2:37:40 
	 * @param festivalActId
	 * @param request
	 * @param response
	 * @param modelMap void
	 * @exception 
	 * @since  1.0.0
	 */
	@RequestMapping(value = "detail")
	public void detail(@RequestParam(required = true) String festivalActId, String userinfoId,
			HttpServletRequest request, HttpServletResponse response,
			ModelMap modelMap) {

		try {
			Map<String, Object> result = new HashMap<String, Object>();
			Map<String, Object> param = new HashMap<String, Object>();
			param.put("festivalActId", festivalActId);
			Czjfestivalact czjfestivalact = festivalactService
					.getCzjfestivalact(param);
			result.put("czjfestivalact", czjfestivalact);
			
			List<Czjfestpic> czjfestpics=czjfestpicService.getCzjfestpicList(param);
			result.put("czjfestpics", czjfestpics);
			// 2017-06-22 13:14:36加， 查询用户活动是否已经预定活动 status=null 未预定  status=0  未支付  status=8 已预定 且支付
			/*param.put("userinfoId",userinfoId);
			String status=festivalactService.getFestAndUserStatus(param);
			result.put("status", status);*/
		
			jsonResult(1, "", "", result, response);
		} catch (Exception e) {
			e.printStackTrace();
			log.error("error",e);
			jsonResult(0, "123", "查询假日活动详情出错", "", response);
		}

	}
	
	/**
	 * 
	 * 方法名：insertFestcomm  新增商品评论
	 * 创建人：RUI
	 * 时间：2017年6月1日-下午5:18:47 
	 * @param request
	 * @param response
	 * @param modelMap void
	 * @exception 
	 * @since  1.0.0
	 */
	@RequestMapping(value = "insertFestcomm")
	public void insertFestcomm(HttpServletRequest request, HttpServletResponse response,
			ModelMap modelMap) {

		try {
		
			// TODO 新增评论
		} catch (Exception e) {
			e.printStackTrace();
			log.error("error",e);
			jsonResult(0, "132", "新增评论错误", "", response);
		}

	}
	
	@RequestMapping(value = "findAllFestcommById")
	public void findAllFestcommById(HttpServletRequest request, HttpServletResponse response,
			ModelMap modelMap) {

		try {
		
			// TODO 查询评论
		} catch (Exception e) {
			e.printStackTrace();
			log.error("error",e);
			jsonResult(0, "133", "查询评论错误", "", response);
		}

	}
	
	@RequestMapping(value = "aa")
	public void aa(HttpServletRequest request, HttpServletResponse response,
			ModelMap modelMap,String aa) throws JsonParseException, JsonMappingException, IOException {

	/*	String b=request.getParameter("users");
		
		ObjectMapper mapper=new ObjectMapper();
		JavaType javaType=mapper.getTypeFactory().constructParametricType(List.class, User.class);
		List<User> s=mapper.readValue(b, javaType);
		System.out.println(s);
		
		
			try {
				jsonResult(1, "a", "aa", "aa", response);
			} catch (Exception e) {
				e.printStackTrace();
			}*/
	}
	
	@RequestMapping("getSumFest")
	public void getSumFest(@RequestParam(required=true) String  festivalActId,HttpServletRequest request, HttpServletResponse response){
		
		try {
			int sumPeople=festivalactService.getSumFest(festivalActId);
			jsonResult(1, "", "", sumPeople, response);
		} catch (Exception e) {
			e.printStackTrace();
			jsonResult(0, "158", "获得报名人数错误", "", response);
		}
		
	}
	

	@Resource
	private CzjfestivalactService festivalactService;
	
	@Resource
	private CzjfestpicService czjfestpicService;

	
	/*@Resource
	private CzjcommentsService czjcommentsService;
	
	@Resource
	private CzjcommentsPicService czjcommentsPicService;
	
	@Resource
	private CzjcommentsVideo czjcommentsVideo;
	
	@Resource
	private CzjreplyService czjreplyService;
	
	@Resource
	private CzjlikeService czjlikeService;*/

}